
const instance = axios.create({
    baseURL: 'http://192.168.2.188:8089',
});

// 请求资源拦截器
instance.interceptors.request.use(
    (config) => {
        // 获取token令牌
        const token = localStorage.getItem('token');
        if (token) {
            // 设置token
            config.headers['Authorization'] = 'Bearer:' + localStorage.getItem("token");
        }
        return config;
    },
    (error) => {
        return Promise.reject(error);
    }
);

// 响应拦截器
instance.interceptors.response.use(res => {
        // 未设置状态码则默认成功状态
        const code = res.data.code || 200;
        //console.log("状态码:"+code);
        return res;
    },
    error => {
        return Promise.reject(error)
    }
)

/*
instance.get('/forum/1')
    .then((response) => {
        console.log(response.data);
    })
    .catch((error) => {
        console.log(error);
    });
*/
